package com.sinocare.project.maintenance.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class ApplicationContextUtils implements ApplicationContextAware {
    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;  //拿到SpringBoot返回的工厂，拿到这工厂就好办了
    }

    //写一个方法，根据Bean的ID或name去工厂中拿相应的对象
    //根据bean名字获得Bean对象
    public static Object getBean(String beanName){
        return context.getBean(beanName);
    }
}
